<?php
/************************************************************************/
/* FrameWork  test preview                                              */
/* ==================================================================== */
/*                                                                      */
/* This program is free software. You can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 2 of the License.       */
/************************************************************************/


$op=$_GET['op'];

?>

<div class='table'>

    <h3 class='bartitle'>Gest Application</h3>

    <p>
<?php
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

if ((defined('LIBGROUP') && group_getusergroup("vbtool",user_getuser())) || admin_isadmin()){

	if($op==""){
?>
<center>
	    <form method="post" action="index.php?appname=<?=$appname;?>&op=crea" method='post'><b><font color="#009900">(creazione applicazione)</font></b><br>
		modello <select name="modello" >
		<?php
		    $fd=opendir("applications/_admin/$subapp/template_applications");
		    while (false !== ($nf= readdir($fd))){
			if( is_dir("applications/_admin/$subapp/template_applications/$nf") && $nf[0]!='.')
			    echo "<option>$nf</option>\n";
		    }
		    closedir($fd);
		?>
		</select><br />
		nome <input size="25" type="text" name="newappl"><br />
		(opzionale) dentro <input size="25" type="text" name="dentroappl"><br />
</font></b><input type="submit" value="crea"> <input type="reset" value="resetta">
	    <br>
</form>
	    </center>
	    <hr>
<center>
	    <form method="post" action="index.php?appname=<?=$appname;?>&op=elimina" method='post'><font color="#ff0000"><b>(eliminazione applicazione)</b></font><br>
		nome <input size="25" type="text" name="delappl"> <br />
		(opzionale) dentro <input size="25" type="text" name="deldentroappl"><br />
<input type="submit" value="elimina"> <input type="reset" value="resetta">
	    </form></center>
<br>
	    <hr>
<center>
	    <form method="post" action="index.php?appname=<?=$appname;?>&op=creabloccosx" method='post'><font color="#ff0000"><b>(creazione blocco SX)</b></font><br>
		modello <select name="modello" >
		<?php
		    $fd=opendir("applications/_admin/$subapp/template_blocks");
		    while (false !== ($nf= readdir($fd))){
			if( is_dir("applications/_admin/$subapp/template_blocks/$nf") && $nf[0]!='.')
			    echo "<option>$nf</option>\n";
		    }
		    closedir($fd);
		?>
		</select><br />
		nome <input size="25" type="text" name="creablocsx"> <br />
<input type="submit" value="crea blocco"> <input type="reset" value="resetta">
	    </form></center>
<br>
	    <hr>
<center>
	    <form method="post" action="index.php?appname=<?=$appname;?>&op=creabloccodx" method='post'><font color="#ff0000"><b>(creazione blocco DX)</b></font><br>
		modello <select name="modello" >
		<?php
		    $fd=opendir("applications/_admin/$subapp/template_blocks");
		    while (false !== ($nf= readdir($fd))){
			if( is_dir("applications/_admin/$subapp/template_blocks/$nf") && $nf[0]!='.')
			    echo "<option>$nf</option>\n";
		    }
		    closedir($fd);
		?>
		</select><br />
		nome <input size="25" type="text" name="creablocdx"> <br />
<input type="submit" value="crea blocco"> <input type="reset" value="resetta">
	    </form></center>



<br>
	    <hr>
<center>
	    <form method="post" action="index.php?appname=<?=$appname;?>&op=delebloccosx" method='post'><font color="#ff0000"><b>(eliminazione blocco SX)</b></font><br>
		nome <input size="25" type="text" name="deleblocsx"> <br />
<input type="submit" value="elimina blocco"> <input type="reset" value="resetta">
	    </form></center>
<br>
	    <hr>
<center>
	    <form method="post" action="index.php?appname=<?=$appname;?>&op=delebloccodx" method='post'><font color="#ff0000"><b>(eliminazione blocco DX)</b></font><br>
		nome <input size="25" type="text" name="deleblocdx"> <br />
<input type="submit" value="elimina blocco"> <input type="reset" value="resetta">
	    </form></center>



<?php
}

//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
if($op=="delebloccosx"){
    // nuova routine per eliminazione applicazione dentro una altra applicazione //
    if ($_POST['deldentroappl']!="") {
	$deldentroappl=$_POST['deldentroappl']."/";
    }
    $delappl=$_POST['deleblocsx'];

    if (file_exists("blocks/left/$deldentroappl".$delappl)){
	$fd=opendir("blocks/left/$deldentroappl".$delappl);
	while (false !== ($nf= readdir($fd))){
	    if ($nf[0]!='.' && $nf[0]!='_'  )
		unlink("blocks/left/$deldentroappl".$delappl."/$nf");
	}
	closedir($fd);
	rmdir("blocks/left/$deldentroappl/$delappl");
    }

    if (file_exists("datas/blocks/left/$deldentroappl".$delappl)){
	$fd=opendir("datas/blocks/left/$deldentroappl".$delappl);
	while (false !== ($nf= readdir($fd))){
	    if ($nf[0]!='.' && $nf[0]!='_'  )
		unlink("datas/blocks/left/$deldentroappl".$delappl."/$nf");
	}
	closedir($fd);
	rmdir("datas/blocks/left/$deldentroappl/$delappl");
    }

    echo "blocco SX eliminato<br />";
    echo "<p align='right'><a href='index.php?appname=$appname'>continua</a></p>";
}
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
if($op=="delebloccodx"){
    // nuova routine per eliminazione applicazione dentro una altra applicazione //
    if ($_POST['deldentroappl']!="") {
	$deldentroappl=$_POST['deldentroappl']."/";
    }
    $delappl=$_POST['deleblocdx'];

    if (file_exists("blocks/right/$deldentroappl".$delappl)){
	$fd=opendir("blocks/right/$deldentroappl".$delappl);
	while (false !== ($nf= readdir($fd))){
	    if ($nf[0]!='.' && $nf[0]!='_'  )
		unlink("blocks/right/$deldentroappl".$delappl."/$nf");
	}
	closedir($fd);
	rmdir("blocks/right/$deldentroappl/$delappl");
    }

    if (file_exists("datas/blocks/right/$deldentroappl".$delappl)){
	$fd=opendir("datas/blocks/right/$deldentroappl".$delappl);
	while (false !== ($nf= readdir($fd))){
	    if ($nf[0]!='.' && $nf[0]!='_'  )
		unlink("datas/blocks/right/$deldentroappl".$delappl."/$nf");
	}
	closedir($fd);
	rmdir("datas/blocks/right/$deldentroappl/$delappl");
    }

    echo "blocco DX eliminato<br />";
    echo "<p align='right'><a href='index.php?appname=$appname'>continua</a></p>";
}

//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
if($op=="creabloccodx"){
    if ($_POST['dentroappl']!="")
	$dentroappl=$_POST['dentroappl']."/";

    $newappl=$_POST['creablocdx'];
    $modello=$_POST['modello'];
    mkdir("datas/blocks/right/$dentroappl".$newappl,0700);
    mkdir("blocks/right/$dentroappl".$newappl,0700);

    $fd=opendir("applications/$appname/template_blocks/$modello/");
    while (false !== ($nf= readdir($fd))){
	if ($nf[0]!='.' && $nf[0]!='_'  )
	    copy( "applications/$appname/template_blocks/$modello/$nf", "blocks/right/".$dentroappl."/".apptitle($newappl)."/$nf");
    }
    closedir($fd);

    echo $modello;
    echo "blocco DX creato<br />";
    echo "<p align='right'><a href='index.php?appname=$appname'>continua</a></p>";
}
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
if($op=="creabloccosx"){
    if ($_POST['dentroappl']!="")
	$dentroappl=$_POST['dentroappl']."/";

    $newappl=$_POST['creablocsx'];
    $modello=$_POST['modello'];
    mkdir("datas/blocks/left/$dentroappl".$newappl,0700);
    mkdir("blocks/left/$dentroappl".$newappl,0700);

    $fd=opendir("applications/$appname/template_blocks/$modello/");
    while (false !== ($nf= readdir($fd))){
	if ($nf[0]!='.' && $nf[0]!='_'  )
	    copy( "applications/$appname/template_blocks/$modello/$nf", "blocks/left/".$dentroappl."/".apptitle($newappl)."/$nf");
    }
    closedir($fd);

    echo "blocco SX creato<br />";
    echo "<p align='right'><a href='index.php?appname=$appname'>continua</a></p>";
}
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
if($op=="crea"){
    if ($_POST['dentroappl']!="")
	$dentroappl=$_POST['dentroappl']."/";

    $newappl=$_POST['newappl'];
    $modello=$_POST['modello'];
    mkdir("datas/applications/$dentroappl".$newappl,0700);
    mkdir("applications/$dentroappl".$newappl,0700);

    $fd=opendir("applications/$appname/template_applications/$modello/");
    while (false !== ($nf= readdir($fd))){
	if ($nf[0]!='.' && $nf[0]!='_'  )
	    copy( "applications/$appname/template_applications/$modello/$nf", "applications/".$dentroappl."/".apptitle($newappl)."/$nf");
    }
    closedir($fd);

    echo "applicazione creata<br />";
    echo "<p align='right'><a href='index.php?appname=$appname'>continua</a></p>";
}
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
if($op=="elimina"){
    // nuova routine per eliminazione applicazione dentro una altra applicazione //
    if ($_POST['deldentroappl']!="") {
	$deldentroappl=$_POST['deldentroappl']."/";
    }
    $delappl=$_POST['delappl'];

    if (file_exists("applications/$deldentroappl".$delappl)){
	$fd=opendir("applications/$deldentroappl".$delappl);
	while (false !== ($nf= readdir($fd))){
	    if ($nf[0]!='.' && $nf[0]!='_'  )
		unlink("applications/$deldentroappl".$delappl."/$nf");
	}
	closedir($fd);
	rmdir("applications/$deldentroappl/$delappl");
    }

    if (file_exists("datas/applications/$deldentroappl".$delappl)){
	$fd=opendir("datas/applications/$deldentroappl".$delappl);
	while (false !== ($nf= readdir($fd))){
	    if ($nf[0]!='.' && $nf[0]!='_'  )
		unlink("datas/applications/$deldentroappl".$delappl."/$nf");
	}
	closedir($fd);
	rmdir("datas/applications/$deldentroappl/$delappl");
    }

    echo "applicazione eliminata<br />";
    echo "<p align='right'><a href='index.php?appname=$appname'>continua</a></p>";
}
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    if($op=="edit"){
	include "applications/$appname/editor.inc";
    }
}
?>

    </p>
</div>
